/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Random;
import java.util.Scanner;

/**
 * <p>Project: app2022 - GuessNumGame
 * <p>Powered by webrx On 2022-01-08 10:56:20
 *
* @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class GuessNumGame {

    public static void main(String[] args) {
        //随机类
        Random rand = new Random();
        //键盘输入
        Scanner sc = new Scanner(System.in);
        //出题
        int num = rand.nextInt(100) + 1;
        int n = 0;
        while (true) {
            ++n;
            int temp = 0;
            System.out.print("请输入数字[1-100]：");
            try {
                temp = sc.nextInt();
            } catch (Exception e) {
                String s = sc.next();
                if ("quit".contains(s)) {
                    sc.close();
                    System.out.printf("程序退出，游戏结束！%n");
                    break;
                }
                System.out.printf("输入有误%s，请重新输入！%n", s);
                continue;
            }

            if (temp > num) {
                System.out.printf("%d、太大了%n", n);
            } else if (temp < num) {
                System.out.printf("%d、太小了%n", n);
            } else {
                if (n == 1) {
                    System.out.printf("大神：你猜对了，你的游戏成绩：%d分", 100);
                } else {
                    System.out.printf("%d、恭喜：你猜对了，你的游戏成绩：%d分", n, 110 - n * 10);
                }
                break;
            }
        }

    }

    public static void ok(String[] args) {
        //随机类
        Random rand = new Random();
        //键盘输入
        Scanner sc = new Scanner(System.in);
        //出题
        int num = rand.nextInt(100) + 1;
        int n = 0;
        while (true) {
            ++n;
            int temp = 0;
            System.out.print("请输入数字[1-100]：");
            if (sc.hasNextInt()) {
                temp = sc.nextInt();
            } else {
                String s = sc.next();
                if ("quit".contains(s)) {
                    sc.close();
                    System.out.printf("程序退出，游戏结束！%n");
                    break;
                }
                System.out.printf("输入有误%s，请重新输入！%n", s);
                continue;
            }

            if (temp > num) {
                System.out.printf("%d、太大了%n", n);
            } else if (temp < num) {
                System.out.printf("%d、太小了%n", n);
            } else {
                if (n == 1) {
                    System.out.printf("大神：你猜对了，你的游戏成绩：%d分", 100);
                } else {
                    System.out.printf("%d、恭喜：你猜对了，你的游戏成绩：%d分", n, 110 - n * 10);
                }
                break;
            }
        }
    }

    public static void error(String[] args) {
        //随机类
        Random rand = new Random();
        //键盘输入
        Scanner sc = new Scanner(System.in);

        //出题
        int num = rand.nextInt(100) + 1;
        int n = 0;
        while (true) {
            ++n;
            int temp = 0;
            System.out.print("请输入数字[1-100]：");

            if (!sc.hasNextInt()) {
                String t = sc.nextLine();
                if ("quit".equals(t)) {
                    System.out.println("游戏退出，程序结束。");
                    sc.close();
                    break;
                } else {
                    System.err.printf("输入有误:%s！\n", t);
                    sc.next();
                }
                --n;
                continue;
            }
            temp = sc.nextInt();

            if (temp > num) {
                System.out.printf("%d、太大了%n", n);
            } else if (temp < num) {
                System.out.printf("%d、太小了%n", n);
            } else {
                if (n == 1) {
                    System.out.printf("大神：你猜对了，你的游戏成绩：%d分", 100);
                } else {
                    System.out.printf("%d、恭喜：你猜对了，你的游戏成绩：%d分", n, 110 - n * 10);
                }
                break;
            }
        }


    }
}
